/*
 * 检验并打印幻方矩阵（4分）
 */

#include <stdio.h>

int main() {
	setbuf(stdout, NULL);

	int input[5][5], buffer_for_sum = 0;
	int temp = 0;

	for (int i = 0; i < 5; ++i) {
		for (int j = 0; j < 5; ++j) {
			scanf("%d", &input[i][j]);
		}
	}

	// 进行检查
	// STEP: 以第一行各元素和为准
	for (int i = 0; i < 5; ++i) {
		buffer_for_sum += input[0][i];
	}
	// STEP: 检查所有行和是否与标准相等
	for (int i = 1; i < 5; ++i) {
		for (int j = 0; j < 5; ++j) {
			temp += input[i][j];
		}
		if (temp != buffer_for_sum) {
			printf("It is not a magic square!\n");
			return 0;
		} else {
			temp = 0;
		}
	}
	// STEP: 检查所有列和是否与标准相等
	for (int i = 0; i < 5; ++i) {
		for (int j = 0; j < 5; ++j) {
			temp += input[j][i];
		}
		if (temp != buffer_for_sum) {
			printf("It is not a magic square!\n");
			return 0;
		} else {
			temp = 0;
		}
	}
	// STEP: 检查所有对角线是否与标准相等
	// 检查主对角线
	for (int i = 0, j = 0; i < 5; ++i, ++j) {
		temp += input[i][j];
	}
	if (temp != buffer_for_sum) {
		printf("It is not a magic square!\n");
		return 0;
	} else {
		temp = 0;
	}
	// 检查副对角线
	for (int i = 0, j = 4; i < 5; ++i, --j) {
		temp += input[i][j];
	}
	if (temp != buffer_for_sum) {
		printf("It is not a magic square!\n");
		return 0;
	} else {
		temp = 0;
	}

	printf("It is a magic square!\n");
	for (int i = 0; i < 5; ++i) {
		for (int j = 0; j < 5; ++j) {
			printf("%4d", input[i][j]);
		}
		printf("\n");
	}

	return 0;
}